package zhihui.mobile.manager.login;


import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

import zhihui.mobile.config.Config;
import zhihui.mobile.config.LoginConfig;
import zhihui.mobile.interfaces.net.IHttpCallBackListener;
import zhihui.mobile.manager.AllManagerObvs;
import zhihui.mobile.manager.IManager;
import zhihui.mobile.net.HttpUtils;

/**
 * Created by 张公铭 on 2017/7/3 0003.
 * 登录相关管理类
 */

public class LoginManager implements IManager
{
    private Logger logger = Logger.getLogger(LoginManager.class);

    private static LoginManager manager;

    private LoginManager()
    {
        AllManagerObvs.getInstance().addManager(this);
    }

    private synchronized static void createdIns()
    {
        if (manager == null)
        {
            manager = new LoginManager();
        }
    }

    public static LoginManager getInstance()
    {
        if (manager == null)
        {
            createdIns();
        }
        return manager;
    }

    /**
     * 用户登录
     */
    public void login(String userName, String password, String code,  String deviceId,String imel,IHttpCallBackListener listener)
    {

        List<Object> values = new ArrayList<>();
        values.add(userName);
        values.add(password);
        values.add(code);
        values.add(deviceId);
        values.add(imel);
        values.add("android");

        HttpUtils.postAes(Config.URL, LoginConfig.geLoginParams(), values, listener);
    }

    @Override
    public void clear()
    {
        AllManagerObvs.getInstance().removeManager(this);
        manager = null;
    }
}
